using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.OracleClient;

namespace GAS.Common.Data
{
	public class GenericMasterTableAdapter
	{
		public static MasterTableType GetDataByMasterTypes<MasterTableType>(IList masterTypes, OracleDataAdapter adapter, OracleConnection connection) where MasterTableType : DataTable, new()
		{
			System.Data.OracleClient.OracleCommand command;
			MasterTableType dataTable;

			if (masterTypes.Count > 0)
			{
				command = new System.Data.OracleClient.OracleCommand();
				command.Connection = connection;
				command.CommandText = "SELECT * "
					//+ "ID, "
					//+ "NAME, "
					//+ "DESCRIPTION, "
					//+ "PARENT_ID, "
					//+ "MASTER_TYPE, "
					//+ "CREATION_DATE, "
					//+ "CREATED_BY, "
					//+ "LAST_UPDATE_DATE, "
					//+ "LAST_UPDATED_BY, "
					//+ "DELETE_MARK "
				+ "FROM GEP_MTS_MASTERTABLE "
				+ "WHERE "
				+ "DELETE_MARK = 0 AND "
				+ "MASTER_TYPE IN ";

				command.CommandType = System.Data.CommandType.Text;

				// Build parameter list
				command.CommandText += "(";
				for (int i = 0; i < masterTypes.Count; i++)
				{
					command.CommandText += ":MasterType" + i + ",";
					command.Parameters.Add(new System.Data.OracleClient.OracleParameter("MasterType" + i, System.Data.OracleClient.OracleType.VarChar, 2, System.Data.ParameterDirection.Input, "", System.Data.DataRowVersion.Current, false, masterTypes[i]));
				}
				command.CommandText = command.CommandText.Substring(0, command.CommandText.Length - 1);
				command.CommandText += ")";


				adapter.SelectCommand = command;
				dataTable = new MasterTableType();
				adapter.Fill(dataTable);

				return dataTable;
			}
			else
				return null;
		}
	}
}
